﻿package vsg.engine {

	import flash.external.ExternalInterface;
	
	
	public class ScriptLoaderGlobalHandle {
		
		
		public static function findUsingImport($str:String):Array {
			var $usingImport = [];
			/**
	 		* the last chara means global research cachea
	 		*/
			var $termExp = new RegExp("using\\(\"[a-zA-Z]+[a-zA-Z\.]*\"\\)" ,"g");
			var $result = null;
			var $className = null;
			try {
				while ( ($result = $termExp.exec($str) ) != null ) {
					$className = $result[0].substring(7 , $result[0].length-2);
					$usingImport.push($className);
				}
		
			} catch (err:Error) {
				ExternalInterface.call("VsEngineCom.flash_debug",err);	
			} finally {
				$className = null;
				$result = null;
				$termExp = null;
			}
			return $usingImport;			
		}
		
		/**
		 * with out using
		 */
		public static function scriptWithOutUsing($org:String):String {
		/**
	 	* the last chara means global research cachea
	 	*/
			var $termExp = new RegExp("using\\(\"[a-zA-Z]+[a-zA-Z\.]*\"\\);" ,"g");
			var $result = null;
			var $className = null;
			try {
				while ( ($result = $termExp.exec($org) ) != null ) {
					$org = $org.replace($termExp,"");
				}
			} catch (err:Error) {
				ExternalInterface.call("VsEngineCom.flash_debug",err);	
			} finally {
				$result = null;
				$className = null;
				$termExp = null;
			}
			return $org;		
			
		}

		
		/**
	 	* execute script source .
	 	*/
		public static function execScriptCode ( $source :String):void {
			try {
				ExternalInterface.call("eval",$source);
			} catch (err:Error) {
				trace(err);
			}			
		}
		
		
	}
	
}